﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xc.DataAccess.Core.Extensions;
namespace Xc.DataAccess.PcpChannels
{
    /// <summary>
    /// 新版本通知请求
    /// </summary>
    public class CloundNewVersionNotifyRequest:RequestFrame
    {
        /// <summary>
        /// 消息码
        /// </summary>
        public override MessageCode MessageCode => MessageCode.NewVersionNotify;
        /// <summary>
        /// 数据域
        /// </summary>
        public override byte[] DataArea 
        {
            get
            {
                if (DesertVersion==null)
                {
                    DesertVersion = string.Empty;
                }
                var data =Encoding.ASCII.GetBytes(DesertVersion);
                byte[] version = new byte[16];
                Array.Copy(data, version, data.Length);
                List<byte> vs=new List<byte>();
                vs.AddRange(version);
                vs.AddRange(PackageSize.FromUInt16BigEndian());
                vs.AddRange(PackageCount.FromUInt16BigEndian());
                vs.AddRange(PackageCheck.FromUInt16BigEndian());
                return vs.ToArray();
            }
        }
        /// <summary>
        /// 目标版本号
        /// </summary>
        public string DesertVersion { get; set; }
        /// <summary>
        /// 分片的大小
        /// </summary>
        public ushort PackageSize { get; set; }
        /// <summary>
        /// 分片总数
        /// </summary>
        public ushort PackageCount { get; set; }
        /// <summary>
        /// 包校验码
        /// </summary>
        public ushort PackageCheck { get; set; }
    }
}
